package com.core.plugin.bind;

import java.util.List;

import com.core.utils.ClassSearcher;
import com.core.utils.ValidateUtil;
import com.jfinal.config.Routes;

/**
 * Routes 自动绑定url和Controller
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public class AutoRouteBindPlugin{
	public static void add(Routes me){
		List<Class> list= ClassSearcher.findClasses();
		if(ValidateUtil.isValid(list)){
			for(Class clz:list){
				Route rb=(Route)clz.getAnnotation(Route.class);
				if(rb!=null){
					me.add(rb.controllerKey(),clz,rb.viewPath());
					System.err.println(clz.getSimpleName()+"--bind--");
				}else{
					System.out.println(clz.getSimpleName()+"--noBind--");
				}
			}
		}
	}
}
